package com.capinfo.accounting.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.capinfo.accumulation.model.accounting.Fzlxsz;
import com.capinfo.accumulation.model.accounting.mybist.GB_JZPZXX;
import com.capinfo.accumulation.model.accounting.mybist.KMSZJBSJ;
import com.capinfo.accumulation.model.pagemodel.Json;
import com.capinfo.accumulation.parameter.accounting.DataGrid;
import com.capinfo.accumulation.service.accounting.mybits.GB_JZPZXXServiceI;
import com.capinfo.accumulation.service.accounting.mybits.HZJZPZServiceI;
import com.capinfo.framework.model.dictionary.Dictionary;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/business/accounting/danjuqueren")
public class DanJuQueRenController{
	@Autowired
	private GB_JZPZXXServiceI gbService;
	@Autowired
	private HZJZPZServiceI hzjzpzservice;
	/**
	 * 跳转到单据页面
	 * @return
	 */
	@RequestMapping("/search.shtml")
	public ModelAndView search(ModelAndView modelAndView,HttpServletRequest request) {
		modelAndView.setViewName("/business/accounting/danjuqueren/test");
		return modelAndView;
	}
	/**
	 * 单据搜索
	 * @param query
	 * @return
	 */
	@RequestMapping("/list.shtml")
	@ResponseBody
	public DataGrid searchRecord(Map map){
		try{
			DataGrid findbyByGrid = gbService.findbyByGrid(map);
			return findbyByGrid;
		}catch (Exception e) {
			e.printStackTrace();
		}
		return new DataGrid();
	}

	@RequestMapping("/update.shtml")
	@ResponseBody
	public Json updateRecord(GB_JZPZXX record){
		Json j = new Json();
		try {
			gbService.updateByPrimaryKeySelective(record);
			j.setSuccess(true);
			j.setMsg("修改成功");
		} catch (Exception e) {
			 e.printStackTrace();
			j.setMsg(e.getMessage());
		}
		return j;
	}

	@RequestMapping("/add.shtml")
	public void createRecord(GB_JZPZXX record){
		gbService.insert(record);
	}
	
	@RequestMapping("/viewPage.shtml")
	public String viewPage(HttpServletRequest request,Map map) {
		try{
			String XSPZH = request.getParameter("XSPZH");
			String HZPZH = request.getParameter("HZPZH");
			map.put("XSPZH", XSPZH);
			map.put("HZPZH", HZPZH);
			DataGrid dd= this.gbService.findbyByGrid(map);
			request.setAttribute("ddList", dd.getRows());
			Map mm=new HashMap();
			mm.put("HZPZH", HZPZH);
			mm.put("XSPZH", XSPZH);
			List<Map<String, Object>> HZ=hzjzpzservice.xianshihsdw(mm);
			request.setAttribute("HZ", HZ);
			return "/business/accounting/danjuqueren/viewPage";
		}catch(Exception e){
			request.setAttribute("erroe",e.getMessage());
			e.printStackTrace();
		}
		return "/business/accounting/danjuqueren/viewPage";
	}
	

	
	@RequestMapping("/editPage.shtml")
	public String editPage(String ID,HttpServletRequest request) {
		GB_JZPZXX gb = gbService.selectByPrimaryKey(ID);
		request.setAttribute("HZJZPZ", gb);
		return "/business/accounting/danjuqueren/update";
	}

	/**
	 * 
	 * @return
	 */

}
